//
//  GFRmView.m
//  Qyer
//
//  Created by dlios on 15/10/26.
//  Copyright (c) 2015年 GF. All rights reserved.
//

#import "GFRmView.h"

@implementation GFRmView

- (instancetype)initWithFrame:(CGRect)frame{
    _buttonArray = [NSMutableArray array];
    _sourceArray = [NSMutableArray array];
    self = [super initWithFrame:frame];
    if (self) {
        [AFN getdataWithString:@"http://open.qyer.com/qyer/search/hot_history?client_id=qyer_android&client_secret=9fcaae8aefc4f9ac4915&v=1&track_deviceid=868842022014563&track_app_version=6.8.1&track_app_channel=xiaomi&track_device_info=hermes&track_os=Android5.0.2&app_installtime=1444898310285&lat=38.883539&lon=121.544848" block:^(id block) {
            _sourceArray = [block objectForKey:@"data"];
            for (int i = 0; i < 4; i++) {
                for (int j = 0; j< 3; j++) {
                    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(10 * WIDTH + 90 * WIDTH * i, 5 * HEIGHT + 35 * HEIGHT * j, 85 * WIDTH, 30 * HEIGHT)];
                    [button setTitle:[_sourceArray objectAtIndex:(i + 4 * j)] forState:UIControlStateNormal];
                    [button.layer setCornerRadius:5.];
//                    button.layer.borderWidth = 2.;
//                    button.layer.borderColor = [UIColor greenColor].CGColor;
                    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
//                    [button setTitleColor:[NightMode shareNightModeHandle].wordColor forState:UIControlStateNormal];
                    [button setBackgroundColor:[UIColor clearColor]];
                    [button setTag:(1000 + i + 4 * j)];
                    [self addSubview:button];
                }
            }
                   } BLOCK:^(id BLOCK) {
            
        }];
        
            
    }
    return self;
}

- (void)buttonClick : (UIButton *)sender{
    NSString *string = [_sourceArray objectAtIndex:sender.tag - 1000];
    NSLog(@"string == %@", string);
    [self.delegate getString:string];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
